package yagl.action;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import com.opensymphony.xwork2.ActionSupport;
import common.MyUtils;

public class DownLoadFileAction extends ActionSupport implements
		ServletRequestAware,ServletResponseAware{
	private String filename;
	private HttpServletRequest request;
	private HttpServletResponse response;
	public String getContentType() {
		return ServletActionContext.getServletContext().getMimeType(request.getSession().getServletContext().getRealPath("/")+ request.getParameter("filePath"));
	}
	public InputStream getDownLoadFile() throws Exception {
			String baseUrl = request.getSession().getServletContext().getRealPath("/");
			// 得到源文件路径
			String sourceFilePath = baseUrl + request.getParameter("filePath");
			String newFileName = new String(request.getParameter("p_fileName").trim().getBytes("ISO8859-1"), "ISO8859-1");
			System.out.println("----------------newFileName"+newFileName);
			this.filename=newFileName.trim()+"."+request.getParameter("p_fileType");
			File file = new File(sourceFilePath);
			InputStream is = new FileInputStream(file);
			return is;
	}
	public String getFilename() {
		return filename;
	}
	
	public void setFilename(String filename) {
		this.filename = filename;
	}

	public String execute() throws Exception {
		return SUCCESS;
	}

	public void setServletRequest(HttpServletRequest arg0) {
		this.request = arg0;
	}
	@Override
	public void setServletResponse(HttpServletResponse arg0) {
		 this.response=arg0;
	}
}
